package com.qlh.composewidget

import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.util.Log
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.GsonUtils

/**
 *作者：70893 on 2025-05-21
 *描述：接收GTC广播
 */

class DealFeeyoReceiver : BroadcastReceiver() {
    private val TAG = javaClass.simpleName

    companion object {
        val ACTION = "com.huawei.dtc.feeyo.task.change"
    }

    override fun onReceive(context: Context, intent: Intent?) {

        val action = intent?.action
        val packName = intent?.`package`
        val task = intent?.getStringExtra("task")?:""
        val close = intent?.getBooleanExtra("close",false)?:false
        Log.e(TAG, "$action----$packName")
        Log.e(TAG, "task----$task")
        Log.e(TAG, "close----$close")

        if (action == ACTION && packName == context?.packageName) {
            if (!task.isNullOrEmpty()){
                val data = GsonUtils.fromJson(task,GtcBO::class.java)
                SendBroadcastActivity.feeyoData.value = data
            }else{
                if (close){
                    //拉取飞友APP
                   ActivityUtils.getTopActivity()?.apply {
                       Intent().apply {
                           val componentName = ComponentName(
                               "com.feeyo.groundservice.lhw_guide",
                               "com.feeyo.groundservice.activity.MainActivity"
                           )
                           setComponent(componentName)
                           startActivity(this)
                       }

                   }
                }
            }
        }
    }
}